package com.yifan.concurrency.ch2;

import javax.servlet.*;
import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicLong;

public class CountingFactorizer implements Servlet {

    private final AtomicLong count = new AtomicLong(0);

    public void init(ServletConfig config) throws ServletException {

    }

    public ServletConfig getServletConfig() {
        return null;
    }

    public void service(ServletRequest req, ServletResponse res) {
        BigInteger i = extractFromRequest(req);
        BigInteger[] factors = factor(i);
        count.incrementAndGet();
        encodeIntoResponse(res, factors);

    }

    private void encodeIntoResponse(ServletResponse res, BigInteger[] factors) {
    }

    private BigInteger[] factor(BigInteger i) {
        //todo
        return null;
    }

    private BigInteger extractFromRequest(ServletRequest req) {
        //todo
        return null;
    }

    public String getServletInfo() {
        return null;
    }

    public void destroy() {

    }

    public AtomicLong getCount() {
        return count;
    }
}
